package dev.mrchen.flows.core;

import java.util.Comparator;

public enum DataLevel implements Comparator<DataLevel> {
    /**
     * 常量
     */
    Constant("C" , 4 ),

    /**
     * 系统级
     */
    System("S" , 3),

    /**
     * 业务级
     */
    Flow("F" , 2),

    /**
     * 运行时变量
     */
    Runtime("R" , 1 );

    private final String prefix;

    private final int level;

    DataLevel(String prefix , int level) {
        this.prefix = prefix;
        this.level = level;
    }

    public DataLevel getHigher() {
        return getByLevel(level+1);
    }

    public DataLevel getLower() {
        return getByLevel(level-1);
    }

    private DataLevel getByLevel( int level ){
        switch (level) {
            case 4: return DataLevel.Constant;
            case 3: return DataLevel.System;
            case 2: return DataLevel.Flow;
            case 1: return DataLevel.Runtime;
            default: return null;
        }
    }

    public String modifyKey( String key ) {
        return this.prefix + "." + key;
    }

    @Override
    public int compare(DataLevel o1, DataLevel o2) {
        return Integer.compare( o1.level , o2.level );
    }


}
